from rest_framework.generics import ListAPIView, CreateAPIView
from rest_framework.permissions import AllowAny
from users.models import User
from rest_framework.pagination import PageNumberPagination #ｄｒｆ自带分页
from meiduo_mall.apps.meiduo_admin.my_pagination import MyPageNumberPagination
from . import user_serializers
#1.获取用户试图
class UserView(ListAPIView,CreateAPIView):
    pagination_class = MyPageNumberPagination
    serializer_class = user_serializers.UserSerializer
    # queryset = User.objects.filter(is_staff=False).all()

    def get_queryset(self):
        #1,获取keyword查询参数

        keyword = self.request.query_params.get('keyword')

        #２，判断是否有keyword
        if keyword:
            return User.objects.filter(is_staff=False,username__contains=keyword).all()

        else:
            return User.objects.filter(is_staff=False).all()

